//
//  SettingFontVC.m
//  VISTA看天下
//
//  Created byon 15/12/6.
//  Copyright © 2015年 . All rights reserved.
//

#import "SettingFontVC.h"

@interface SettingFontVC()
{
    
}
@property (nonatomic, strong)UILabel *textLabel;
@property (nonatomic, strong)NSMutableArray *btnArray;
@property (nonatomic, strong)UIView *btnView;
@property (nonatomic, strong)UIImage *segImg;
@end
@implementation SettingFontVC




- (void)viewDidLoad
{
    self.font = @"中";
    _btnArray = [NSMutableArray array];
    [self configNavi];
    [self createView];
}


- (void)configNavi
{
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NAVI"] forBarMetrics:UIBarMetricsDefault];
    
    //定制导航栏左按钮
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 50, 32);
    [leftButton setImage:[UIImage imageNamed:@"返回_1"] forState:UIControlStateNormal];
    [leftButton setImage:[UIImage imageNamed:@"返回_2"] forState:UIControlStateHighlighted];
    [leftButton addTarget:self action:@selector(pop) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftItem;
    //导航栏标题
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];
    titleLabel.text = self.title;
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
}
- (void)pop
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)createView
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(20, 76, 285, 317)];
    view.layer.cornerRadius = 6;
    view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"字号背景.png"]];
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15 , 15, view.frame.size.width-20, 15)];
    titleLabel.text = @"你当前的文章字号是:";
    titleLabel.textColor = [UIColor redColor];
    
    _btnView = [[UIView alloc]initWithFrame:CGRectMake((view.frame.size.width-174)/2, 40, 174, 25)];

    if ([_font isEqualToString:@"大"]) {
        _segImg = [UIImage imageNamed:@"大字号.png"];
    }else if ([_font isEqualToString:@"中"]) {
        _segImg = [UIImage imageNamed:@"中字号.png"];
    }else if ([_font isEqualToString:@"小"]) {
        _segImg = [UIImage imageNamed:@"小字号.png"];
    }
    _btnView.backgroundColor = [UIColor colorWithPatternImage:_segImg];
    
    for (int i = 0; i < 3; i ++) {
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake((174/3)*i, 0, 174/3, 25)];
        button.backgroundColor = [UIColor clearColor];
        [button addTarget:self action:@selector(changeFont:) forControlEvents:UIControlEventTouchUpInside];
        [self.btnArray addObject:button];
        [_btnView addSubview:button];
    }
   
    
    
    
   
    
    
    _textLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, view.frame.size.width-20, view.frame.size.height-50)];
    _textLabel.text = @"欢迎使用本客户端,为了达到更好的阅读体验和浏览效果,请按动上方＂大　中　小＂三个按钮,调整字体大小,以适应您的阅读习惯,谢谢.";
    _textLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _textLabel.numberOfLines = 0;
    
    [view addSubview:_textLabel];
    [view addSubview:titleLabel];
    [view addSubview:_btnView];
    [self.view addSubview:view];
}
- (void)changeFont:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    NSUInteger index = [_btnArray indexOfObject:btn];
    switch (index) {
            NSLog(@"%ld",(unsigned long)index);
        case 0:
            self.btnView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"大字号.png"]];
            self.font = @"大";
            self.textLabel.font = [UIFont systemFontOfSize:18];
            break;
        case 1:
            self.btnView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"中字号.png"]];
            self.font = @"中";
            self.textLabel.font = [UIFont systemFontOfSize:15];
            break;
        case 2:
            self.btnView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"小字号.png"]];
            self.font = @"小";
            self.textLabel.font = [UIFont systemFontOfSize:12];
            break;
            
        default:
            break;
    }
    
}
- (void)change
{
    
}

@end
